package com.ihg.hiex.admin.service.session.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.utils.CollectionUtils;
import com.ihg.hiex.admin.dao.account.AssessorDao;
import com.ihg.hiex.admin.dao.account.DelegateDao;
import com.ihg.hiex.admin.dao.session.SessionParticipatorDao;
import com.ihg.hiex.admin.service.DataServiceImpl;
import com.ihg.hiex.admin.service.session.SessionParticipatorService;
import com.ihg.hiex.entity.session.Session;
import com.ihg.hiex.entity.session.participator.SessionParticipator;
import com.ihg.hiex.entity.user.Assessor;
import com.ihg.hiex.entity.user.Delegate;

/**
 *
 * @author Ark
 *
 */
@Service("sessionParticipatorService")
public class SessionParticipatorServiceImpl extends DataServiceImpl<SessionParticipator> implements SessionParticipatorService {

    @Dao
    private SessionParticipatorDao sessionParticipatorDao;
    
    @Dao
    private AssessorDao assessorDao;
    
    @Dao
    private DelegateDao delegateDao;
    
    /* (non-Javadoc)
     * @see com.ihg.hiex.assessment.service.session.SessionParticipatorService#listAssessor(com.ihg.hiex.entity.session.Session)
     */
    @SuppressWarnings("unchecked")
    public List<Assessor> listAssessor(Session session) {
        
        List<SessionParticipator> participators = sessionParticipatorDao.list(session);
        List<Long> assessorIds = CollectionUtils.extractPropertyList(participators, "assessorId");
        
        List<Assessor> assessors = assessorDao.list(assessorIds);
        return assessors;
        
    }
    
    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.admin.service.SessionParticipatorService#listDelegate(com.ihg.hiex.entity.session.Session)
     */
    @SuppressWarnings("unchecked")
    public List<Delegate> listDelegate(Session session) {
        List<SessionParticipator> participators = sessionParticipatorDao.list(session);
        List<Long> delegateIds = CollectionUtils.extractPropertyList(participators, "delegateId");
        
        List<Delegate> delegates = delegateDao.list(delegateIds);
        return delegates;
    }
    
    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.admin.service.session.SessionParticipatorService#listDelegateId(com.ihg.hiex.entity.session.Session)
     */
    @SuppressWarnings("unchecked")
    public List<Long> listDelegateId(Session session) {
        List<SessionParticipator> participators = sessionParticipatorDao.list(session);
        return CollectionUtils.extractPropertyList(participators, "delegateId");
    }

    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.assessment.service.session.SessionParticipatorService#listLeadParticipator(com.ihg.hiex.entity.session.Session, java.lang.Long)
     */
    public List<SessionParticipator> listLeadParticipator(Session session, Long assessorId) {
        return sessionParticipatorDao.list(session, assessorId);
    }

    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.assessment.service.session.SessionParticipatorService#listPeerParticipator(com.ihg.hiex.entity.session.Session, java.lang.Long, java.lang.String)
     */
    public List<SessionParticipator> listPeerParticipator(Session session, Long assessorId, String subgroup) {
        return sessionParticipatorDao.list(session, subgroup, assessorId);
    }
    
    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.admin.service.SessionParticipatorService#list(com.ihg.hiex.entity.session.Session)
     */
    public List<SessionParticipator> list(Session session) {
        return sessionParticipatorDao.list(session);
    }
    
    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.assessment.service.session.SessionParticipatorService#list(com.ihg.hiex.entity.session.Session, java.lang.String)
     */
    public List<SessionParticipator> list(Session session, String subgroup) {
        return sessionParticipatorDao.listByGroup(session, subgroup);
    }
    
    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.assessment.service.session.SessionParticipatorService#load(com.ihg.hiex.entity.session.Session, java.lang.Long)
     */
    public SessionParticipator loadByDelegate(Session session, Long delegateId) {
        return sessionParticipatorDao.loadByDelegate(session, delegateId);
    }
    
    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.admin.service.session.SessionParticipatorService#loadByDelegate(java.lang.Long)
     */
    public SessionParticipator loadByDelegate(Long delegateId) {
        return sessionParticipatorDao.loadByDelegate(delegateId);
    }
    
    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.assessment.service.session.SessionParticipatorService#loadByAssessor(com.ihg.hiex.entity.session.Session, java.lang.Long)
     */
    public SessionParticipator loadByAssessor(Session session, Long assessorId) {
        return sessionParticipatorDao.loadByAssessor(session, assessorId);
    }
    
    /*
     * (non-Javadoc)
     * @see com.ihg.hiex.assessment.service.session.SessionParticipatorService#loadPeerParticipator(com.ihg.hiex.entity.session.Session, java.lang.String, java.lang.Long)
     */
    public SessionParticipator loadPeerParticipator(Session session, String subgroup, Long assessorId) {
        return sessionParticipatorDao.load(session, subgroup, assessorId);
    }
    
}
